package com.kang.controller;

import com.kang.entity.Field;
import com.kang.entity.Table;
import com.kang.service.TableService;
import com.kang.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: Java_new_sql
 * @description:
 * @author: K.faWu
 * @create: 2021-06-15 18:14
 **/

@RestController
@RequestMapping("table")
public class TableController {
    @Autowired
    private TableService tableService;

    @PostMapping
    public Result addTable(@RequestBody Table table){
//        Field field1 = new Field("", "id", "int", "", true);
//        //Field field2 = new Field("", "name", "varchar(10)", "名字", false);
//        List<Field> fieldList = new ArrayList<>();
//        fieldList.add(field1);
//        //fieldList.add(field2);
//        Table table = new Table("student", fieldList);
        if(CollectionUtils.isEmpty(table.getFieldList())){
            return Result.failure("未输入字段");
        }
        tableService.addTable(table);
        return Result.success();
    }
}
